package cn.com.ntr.jhclient.db;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import cn.com.ntr.jhclient.model.Profession;

public class DBProfession implements DBInterface<Profession> {
	private DatabaseHelper helper;

	public DBProfession(Context context) {
		helper = new DatabaseHelper(context);
	}

	@Override
	public long insert(Profession t) {
		// TODO Auto-generated method stub
		ContentValues values = new ContentValues();
		values.put(Profession.PID, t.getpId());
		values.put(Profession.P_NAME, t.getpName());
		values.put(Profession.P_ENNAME, t.geteName());
		values.put(Profession.P_FID, t.getfId());
		values.put(Profession.P_ORDER, t.getOrderId());
		return helper.insertData(CreateDbConstants.TABLE_PROFESSION, values);
	}

	@Override
	public List<Profession> queryAll() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public List<Profession> queryPro() {
		List<Profession> list = new ArrayList<Profession>();
		SQLiteDatabase db = helper.getWritableDatabase();
		Cursor cursor = db.rawQuery("select * from "
				+ CreateDbConstants.TABLE_PROFESSION + " where "
				+ Profession.P_FID + "=?", new String[] { "0" });
		while (cursor.moveToNext()) {
			Profession obj = new Profession();
			obj.setpId(cursor.getString(cursor
					.getColumnIndex(Profession.PID)));
			obj.setpName(cursor.getString(cursor
					.getColumnIndex(Profession.P_NAME)));
			list.add(obj);
		}
		return list;
	}

	public List<Profession> querySubPro(String pid) {
		List<Profession> list = new ArrayList<Profession>();
		SQLiteDatabase db = helper.getWritableDatabase();
		Cursor cursor = db.rawQuery("select * from "
				+ CreateDbConstants.TABLE_PROFESSION + " where "
				+ Profession.P_FID + "=?", new String[] { pid });
		while (cursor.moveToNext()) {
			Profession obj = new Profession();
			obj.setpName(cursor.getString(cursor
					.getColumnIndex(Profession.P_NAME)));
			obj.setpId(cursor.getString(cursor
					.getColumnIndex(Profession.PID)));
			list.add(obj);
		}
		return list;
	}
	
}
